package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    @AutoFill(value = OperationType.INSERT)
   /* @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into dish(name, category_id, price, image, description, create_time, update_time, create_user, update_user) " +
            "values (#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser})")*/
    void insert(Dish dish);

    List<DishVO> page(DishPageQueryDTO dishPageQueryDTO);


    void deleteDishByid(List<Long> ids);

    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);



    @Select("select d.category_id as 'categoryId' from dish as d,category as c where d.category_id = c.id and d.id = #{id}")
    Long getCategoryIdByID(Long id);

    List<DishFlavor> getDishFlavorByDishID(Long id);

    @AutoFill(value = OperationType.UPDATE)
    void updateDish(Dish dish);



    List<Dish> list(Dish dish);


    /**
     * 根据套餐id查询菜品
     * @param setmealId
     * @return
     */
    @Select("select a.* from dish a right join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

}
